package cn.z2huo.knowledge.concurrency.completablefuture;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
class CompletableFutureTest {

    public static void main(String[] args) {
        CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
            log.info("No. 0");
            ThreadUtil.sleep(10, TimeUnit.SECONDS);
            return "zyz";
        }).thenApply(x -> {
            log.info("No. 2, value is {}", x);
            ThreadUtil.sleep(10, TimeUnit.SECONDS);
            return x + " hhh";
        }).thenAcceptAsync(y -> {
            log.info("No. 3, value is {}", y);
            ThreadUtil.sleep(10, TimeUnit.SECONDS);
        });

        future.join();
    }
}
